package ar.com.cooker.spider.ut;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;


public class PropertyManager {

	public static final String FILENAME = "spider.properties";
	
	public static final String USE_PROXY  = "useProxy";
	public static final String PROXY_HOST  = "proxy.host";
	public static final String PROXY_PORT = "proxy.port";
	public static final String PAGE = "mis-recetas.org.urlStart";
	public static final String DOMAIN = "mis-recetas.org.baseDomain";
	 
	

	
	private Properties prop = null;
	private static PropertyManager instance = null;
	private FileInputStream fis = null;
		
	private PropertyManager(){
		
		try {
			prop = new Properties();
			fis  = new FileInputStream(PropertyManager.FILENAME);
			prop.load(fis);		
		} catch(IOException e) {
			e.printStackTrace();
		}
	}
	
	public void closeFile(){
		try {
			fis.close();
			prop = null;			
		} catch (IOException e) {
			System.out.println("Se produjo el siguiente error al "+
					"querer cerrar el archivo de properties: ");
			e.printStackTrace();
		}
	}
	
	public static PropertyManager getInstance(){
		if(instance==null || instance.prop == null) 
			instance = new PropertyManager();
		return instance;
	}
	
	public String getProperty(String clave){
		return prop.getProperty(clave);
	}
	public boolean getUseProxy(){
		try{
			return Boolean.parseBoolean(prop.getProperty(PropertyManager.USE_PROXY));
		}catch(Exception e){
			return false;
		}
	}
	
	public String getProxyHost(){
		return prop.getProperty(PropertyManager.PROXY_HOST);
	}
	public String getProxyPort(){
		return prop.getProperty(PropertyManager.PROXY_PORT);
	}
	public String getStartPage(){
		return prop.getProperty(PropertyManager.PAGE);
	}
	public String getBaseDomain(){
		return prop.getProperty(PropertyManager.DOMAIN);
	}
}
